#include "happly.hpp"
#include <GL/glut.h>
#include <GL/glu.h>
#include <GL/gl.h>
int width = 640;
int height = 480;

happly::PLYData obj("cube.ply");

void Initialize()
{
	glClearColor(0.5, 0.5, 0.5, 0.0);
	glEnable(GL_DEPTH_TEST);
}

void Reshape(int w, int h)
{
	width = w;
	height = h;
	glViewport(0, 0, width, height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0, (double)width / (double)height, 1.0, 100.0);
}

void Display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glViewport(0, 0, width, height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	// glTranslatef(0.7, -0.3, 0);
	// glRotatef(280, 1, 0, 0);
	// glRotatef(80, 0, 0, 1);
	// glScalef(5, 5, 5);

	glEnableClientState(GL_VERTEX_ARRAY);
	// glEnableClientState(GL_NORMAL_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);
	glVertexPointer(3, GL_FLOAT, 0, obj.getVertexPositions().data());
	glColorPointer(3, GL_FLOAT, 0, obj.getVertexColors().data());
	// glNormalPointer(GL_FLOAT, 0, m_ModelData.vecNormals.data());
	// glDrawArrays(GL_TRIANGLES, 0, m_ModelData.iTotalConnectedTriangles);
	glDisableClientState(GL_VERTEX_ARRAY);
	// glDisableClientState(GL_NORMAL_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);

	glutSwapBuffers();
}

int main(int argc, char **argv)
{
	glutInit(&argc, argv);
	glutInitWindowPosition(0, 0);
	glutInitWindowSize(width, height);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
	glutCreateWindow("Load Model");
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);

	Initialize();

	glutMainLoop();

	return 0;
}